        <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$("#tanggal").datetimepicker({
					changeMonth: true,
				    changeYear: true,
				    showOtherMonths: true,
					dateFormat:'yy-mm-dd',
					timeFormat: 'hh:mm:ss',
			        hourGrid: 8,
			        minuteGrid: 10,		
				});
			} );
		</script>
<?php
if($_SESSION['rts']!=1){
	echo "Akses tidak diizinkan";
	exit();
}

$act = filter($_GET['act']);
$field = filter($_GET['field']);
$q = filter($_GET['q']);

if(empty($act)){	
?>		
					<!-- box / title -->
					<div class="title">
						<h5>Data Ready To Sale </h5>								
						<div class="search global-nav">
							<form method="GET" class="form-search js-search-form" action="index.php?pages=rts" id="global-nav-search" style="width:350px">
								<input type="hidden" name="pages" value="rts">
								<select name="field" id="birthday_month" aria-label="Month" class="" >
									<option value="" <?php echo ($field=="")?"selected":"";?>>Cari Berdasarkan:</option>
									<option value="id_prod" <?php echo ($field=="id_prod")?"selected":"";?>>Kode Produksi</option>									
									<option value="status" <?php echo ($field=="status")?"selected":"";?>>Status</option>
									<option value="status_asal" <?php echo ($field=="status_asal")?"selected":"";?>>Status Asal</option>									
								</select>

				            	<label class="visuallyhidden" for="search-query">Search query</label>
				            	<input class="search-input" type="text" id="search-query" placeholder="Search" name="q" value="<?php echo $q;?>">
				            	<span class="search-icon js-search-action">
				              		<button type="submit" class="icon nav-search" tabindex="-1">
				              			<span class="visuallyhidden">Search</span>
				              		</button>
				            	</span>
				            	<input disabled="disabled" class="search-input search-hinting-input" type="text" id="search-query-hint" autocomplete="off" spellcheck="false">				              					              
							</form>
						</div>
					</div>
					<!-- end box / title -->
					<div class="table">										
						<table>
							<thead>
								<tr>
									<th class="selected"><input type="checkbox" class="checkall" /></th>
									<th class="action">No.</th>
									<th>Kode  Produksi</th>
									<th>Jumlah</th>
									<th>Satuan</th>
									<th>Status</th>
									<th>Tanggal</th>
                                    <th>Status Asal</th>
									<th class="action" colspan="2"><!--<a href="?pages=rts&act=edit" class="icon-plus-sign" title="Tambah Data Baru"></a> --></th>									
								</tr>
							</thead>
							<tbody>
							<?php			

							$q2=$q;
							if($field=='status'){
								$q2 = (strtolower($q)=='diterima')?'1':'0';
							}
							
							if($field=='status_asal'){
								$q2 = (strtolower($q)=='barang perbaikan')?'1':'0';
							}
							
							$addQuery='';


							if(!empty($field))
								$addQuery .= " WHERE $field LIKE '%$q2%' ";

							$batas=10;
							$pg=(int) $_GET['pg'];
							if(empty($pg))
							{
								$posisi=0;
								$pg=1;
							}
							else
							{
								$posisi = ($pg-1) * $batas;
							}
							$sqlrts1 = mysql_query("SELECT tb_rts.*, tb_produksi.kode_prod FROM tb_rts $addQuery 
													LEFT JOIN tb_produksi ON (tb_rts.id_prod=tb_produksi.id_produksi)
													ORDER BY id_rts DESC LIMIT $posisi, $batas");							
							$no=$posisi+1;
							while($dataRts = mysql_fetch_array($sqlrts1)){								

								$status_asal = ($dataRts['status_asal']==1)? "Barang Kembali":"Barang Produksi";
								if($dataRts['status_asal']==1){
									$status_asal = "Barang Kembali";
								}elseif ($dataRts['status_asal']==0) {
									$status_asal = " Barang Produksi";
								}else{
									$status_asal = " Barang Sisa Produksi";
								}

								$status = ($dataRts['status']==1)? "<div class=icon-ok>&nbsp;</div>":"<div class=icon-remove>&nbsp;</div>";
							?>
								<tr>
									<td class="selected"><input type="checkbox" /></td>
									<td class="center"><?php echo $no;?></td>
									<td><?php echo $dataRts['kode_prod'];?></td>
									<td class="center"><?php echo $dataRts['jumlah'];?></td>
									<td class="center"><?php echo $dataRts['satuan'];?></td>
									<td class="center"><?php echo $status;?></td>
									<td><?php echo $dataRts['tgl'];?></td>
                                    <td><?php echo $status_asal;?></td>
									<td class="action"><a href="?pages=rts&act=edit&id=<?php echo $dataRts['id_rts'];?>" class="icon-edit" title="Ubah Data"></a></td>					
								</tr>
							<?php	
								$no++;				
							}

							$sqlSup2 = mysql_query("SELECT * FROM tb_rts $addQuery ORDER BY id_rts DESC");
							$jumlahData = mysql_num_rows($sqlSup2);

							$file="?pages=rts&field=$field&q=$q";
							$jmlhalaman=ceil($jumlahData/$batas);
	
							?>															
							</tbody>
						</table>
						<!-- pagination -->
						<div class="pagination pagination-left">
							<div class="results">
								<span><?php echo "Showing Results ".($posisi+1)."-".($no-1)." of $jumlahData";?></span>
                                <?php
						$sqlRts = mysql_query("SELECT stock_rts FROM tb_temp_rts LIMIT 1");
						$getRts = mysql_fetch_array($sqlRts);
						?>
						<p>&nbsp;</p><br />
						<p style="font:bold 14px Tahoma"><i>Total Stock Ready to Sale : <?php echo $getRts['stock_rts'];?> Karton</i><div class="report">
						  <form method="post" action="print_rts.php" >
					<table width="185" border="1">
  <tr>
    <td width="68">Pilih Bulan</td>
    <td width="101"><select name="bulan" id="bulan">
                                                                <option label="January" value="01" selected="selected">January</option>
                                                                <option label="February" value="02">February</option>
                                                                <option label="March" value="03">March</option>
                                                                <option label="April" value="04">April</option>
                                                                <option label="May" value="05">May</option>
                                                                <option label="June" value="06">June</option>
                                                                <option label="July" value="07">July</option>
                                                                <option label="August" value="08">August</option>
                                                                <option label="September" value="09">September</option>
                                                                <option label="October" value="10">October</option>
                                                                <option label="November" value="11">November</option>
                                                                <option label="December" value="12">December</option>
                                                              </select></td>
    </tr>
  <tr>
    <td colspan="2" align="center"><span class="i"><input type="submit" name="submit" value="Print" /></span></td>
    </tr>
</table>

                                
</form></div></p>
					    </div>
							<ul class="pager">
								<?php
								//link ke halaman sebelumnya (previous)
								if($pg > 1){
									$previous=$pg-1;
									echo "<li><a href=$file&pg=1>&laquo; First</a></li>
									<li><a href=$file&pg=$previous>&laquo; Prev</a></li> ";
								}else{ 
									echo "<li class='disabled'>&laquo; First</li>
									<li class='disabled'>&laquo; Prev</li> ";
								}
								?>

								<?php
								//Link untuk Angka
								$angka=($pg > 3 ? " <li class='separator'>...</li> " : " ");
								for($i=$pg-2;$i<$pg;$i++)
								{
								  if ($i < 1) 
								      continue;
								  $angka .= "<li><a href='$file&pg=$i'>$i</a></li> ";
								}

								$angka .= " <li class='current'>$pg</li>";
								for($i=$pg+1;$i<($pg+3);$i++)
								{
								  if ($i > $jmlhalaman) 
								      break;
								  $angka .= "<li><a href='$file&pg=$i'>$i</a></li> ";
								}

								$angka .= ($pg+2<$jmlhalaman ? " <li class='separator'>...</li> <li><a href='$file&pg=$jmlhalaman'>$jmlhalaman</a></li>" : " ");

								echo "$angka";
								?>
								

								<?php
								//link kehalaman berikutnya (Next)
								if($pg < $jmlhalaman)
								{
									$next=$pg+1;
									echo "<li><a href='$file&pg=$next'>Next &raquo;</a></li>
									<li><a href='$file&pg=$jmlhalaman'>Last &raquo;</a></li>";
								}
								else
								{ 
									echo "<li class='disabled'>Next &raquo;</li>
									<li class='disabled'>Last &raquo;</li> ";
								}		
								?>													
							</ul>
					  </div>

						<!-- end pagination -->
						<!-- table action -->
						
						<!-- end table action -->	
										
					</div>

<?php
}elseif ($act=='edit') {

	$id_rts = (int) filter($_GET['id']);
	
	$sqlSup = mysql_query("SELECT tb_rts.*, tb_produksi.kode_prod FROM tb_rts
							LEFT JOIN tb_produksi ON (tb_rts.id_prod=tb_produksi.id_produksi)
							WHERE id_rts=$id_rts");
	$dataRts = mysql_fetch_array($sqlSup);
	$status = ($dataRts['status']==1)? "checked":"";
	if(!empty($id_rts)){
		?>
		<!-- box / title -->
		<div class="title">
			<h5>Ubah Data Ready To Sale </h5>														
		</div>
		<!-- end box / title -->
		<?php
	}else{
		?>
		<!-- box / title -->
		<div class="title">
			<h5>Tambah Data Ready To Sale </h5>														
		</div>
		<!-- end box / title -->
		<?php
	}

?>	

	<div class="table">
		<form method="POST" action="?pages=rts&act=update">
		<input type="hidden" name="id_rts" value="<?php echo $dataRts['id_rts'];?>">
		<table style="width:auto">
		   	<tbody>
		   		<tr>
					<td><label>Kode  Produksi</label></td>
					<td>:</td>
					<td><input type="text" value="<?php echo $dataRts['kode_prod'];?>" size="60" name="id_prod" id="id_prod" readonly="true"></td>
			   	</tr>
			   	<tr>
					<td><label>Jumlah</label></td>
					<td>:</td>
					<td><input type="text" value="<?php echo $dataRts['jumlah'];?>" size="60" name="jumlah" id="jumlah" readonly="true"></td>
			   	</tr>
			   	<tr>
					<td><label>Satuan</label></td>
					<td>:</td>
					<td><input type="text" value="<?php echo $dataRts['satuan'];?>" size="60" name="satuan" id="satuan" readonly="true"></td>
			   	</tr>
			   	<tr>
					<td style="vertical-align: top;"><label>Status Terima </label></td>
					<td>:</td>
					<td>
				 		<input type="checkbox" name="status" id="status" <?php echo $readonly;?>  <?php echo $status;?>>
				 	</td>
			   	</tr>
			   	<tr>
					<td><label>Tanggal</label></td>
					<td>:</td>
				 	<td><input type="text" value="<?php echo $dataRts['tgl'];?>" size="60" name="tanggal" id="tanggal" placeholder="Tanggal" required></td>
			   	</tr>
				<tr>
					<td style="vertical-align: top;"><label>Status Asal</label></td>
					<td>:</td>
					<td><input type="text" value="<?php echo ($dataRts['status_asal']==1)? "Barang Kembali":"Barang Produksi";?>" size="60" name="status_asal" id="status_asal" readonly="true"></td>
			   	</tr>
			 	<tr>
			 		<td>&nbsp;</td>
			 		<td>&nbsp;</td>
			 		<td>
			 			<input type="hidden" value="" size="15" name="id">
						<input type="submit" value="Simpan" name="submit" class="btn btn-primary">
						<input type="Reset" value="Reset" class="btn">
			 		</td>
		   		</tr>
		 	</tbody>
		</table>
		</form>
	</div>
<?php
}elseif ($act=='update') {
	# code...
	$id_rts = (int) $_POST['id_rts'];
	$status = (isset($_POST['status']))? '1':'0';
	$tanggal = $_POST['tanggal'];


	if(!empty($id_rts)){
	
		$sql_cek = mysql_query("SELECT * from tb_rts WHERE id_rts=$id_rts");
		$cek = mysql_fetch_array($sql_cek);
		$jumlah_rts = $cek['jumlah'];		
		
		$sql_temp = mysql_query("SELECT * FROM tb_temp_rts WHERE id_temp = 1 ");
		$j_stok = mysql_fetch_array($sql_temp);
		
		if($status==1){
			$jml_stok = $j_stok['stock_rts'] + $jumlah_rts;
		}elseif($status==0){
			$jml_stok = $j_stok['stock_rts'] - $jumlah_rts;
		}
		
		$sql_update_stok = mysql_query("UPDATE tb_temp_rts SET stock_rts = $jml_stok WHERE id_temp='1'");

		if($sql_update_stok){
			$update = mysql_query("UPDATE tb_rts SET status='$status', tgl='$tanggal' WHERE id_rts=$id_rts");
		}
			
		if($update){
			sukses('Data berhasil disimpan', '?pages=rts');
		}
	}	
}
?>					